@extends('admin.common.list.list')
@section('content')
<div class="mws-panel grid_8">
	<div class="mws-panel-header">
        <span><i class="icon-table"></i> 修改网站配置
    </div>
    <div class="mws-panel-body no-padding">
    		<form action="" id="art_form" method="post"  enctype="multipart/form-data">
            {{csrf_field()}}
            {{method_field('put')}}
            <div class="mws-form-inline" height="800px">
                <div class="mws-form-row">
                    <label class="mws-form-label">网站名称</label>
                    <div class="mws-form-item">
                        <input type="text" class="small" name="a_name" id="a_name" value="{{$conf->c_name}}" >
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">网站logo</label>
                    <div class="mws-form-item">
                        <input type="text" name="art_thumb" id="art_thumb" value="{{$conf->c_logo}}">
                            {{--文件上传插件--}}
                            <input id="file_upload" name="file_upload" type="file" multiple="true" form="uploadform">

                            <p><img id="img1" src="{{$conf->c_logo}}" alt="上传后显示图片"  style="max-width:180px;max-height:40px;" /></p>
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">网站状态</label>
                    <div class="mws-form-item">
                        <input type="radio"  name="c_status" {{$conf->c_status==0?'checked':''}}>开启
                        <input type="radio"  name="c_status" {{$conf->c_status==1?'checked':''}}>关闭
                    </div>
                </div>
            </div>
            <div class="mws-button-row">
                <input type="submit" value="修改" class="btn btn-danger">
                <input type="button" value="返回"  onclick="window.history.back()" class="btn ">
            </div>
        </form>
    </div>    	
</div>
<script type="text/javascript">
        $(function () {
            $("#file_upload").change(function () {
                uploadImage();
            });
        });

        function uploadImage() {
//                            判断是否有选择上传文件
            var imgPath = $("#file_upload").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1).toLowerCase();
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
//                            var myform = document.getElementById('art_from');
            var formData = new FormData($('#art_form')[0]);
            {{--formData.append('_token', '{{csrf_token()}}');--}}
                                        {{--console.log(formData);--}}
            $.ajax({
                type: "put",
                url: "/t_admin/config",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                                   console.log(data);
                                   alert("上传成功");
                    $('#img1').attr('src','/'+data);
                    $('#art_thumb').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }

    </script>

@endsection